package com.example.day03_mvp.fragment;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.day03_mvp.R;
import com.example.day03_mvp.adapter.WanAdapter;
import com.example.day03_mvp.base.BaseFragment;
import com.example.day03_mvp.base.BasePresenter;
import com.example.day03_mvp.bean.WanBean;
import com.example.day03_mvp.presenter.WanPresenter;
import com.example.day03_mvp.view.WanView;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends BaseFragment<WanPresenter> implements WanView {
    @BindView(R.id.home_re)
    RecyclerView home_e;
    private ArrayList<WanBean.DataBean.DatasBean> datasBeans;
    private WanAdapter wanAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        home_e.setLayoutManager(new LinearLayoutManager(getContext()));
        home_e.addItemDecoration(new DividerItemDecoration(getContext(),LinearLayoutManager.VERTICAL));
        datasBeans = new ArrayList<>();
        wanAdapter = new WanAdapter(getContext(), datasBeans);
        home_e.setAdapter(wanAdapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter=new WanPresenter();
        mPresenter.getdata();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_home;
    }

    @Override
    public void onSuccess(WanBean data) {
        datasBeans.addAll(data.getData().getDatas());
        wanAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {
        Toast.makeText(getContext(),error,Toast.LENGTH_LONG).show();
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(getContext(),str,Toast.LENGTH_LONG).show();

    }
}
